﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.Mirror.Ia32
{
	public class Ia32Disassembly : Ia32DisassemblyBase
	{
		internal Ia32Disassembly(
			long baseAddress,
			int procedureLength,
			IEnumerable<Ia32DisassemblyBlock> blocks,
			IEnumerable<NativeDependency> dependencies
			)
			: base(baseAddress, procedureLength)
		{
			this.Blocks = blocks;
			this.Dependencies = dependencies;
		}

		public override bool ContainsAddress(long address)
		{
			bool containsAddress = this.Blocks.Any(block => block.ContainsAddress(address));
			return containsAddress;
		}

		public override IEnumerable<Ia32Instruction> Instructions
		{
			get { return this.BlocksByAddress.SelectMany(b => b.Instructions); }
		}

		public IEnumerable<Ia32Instruction> InstructionsByBlock
		{
			get { return this.Blocks.SelectMany(b => b.Instructions); }
		}

		public IEnumerable<Ia32DisassemblyBlock> Blocks { get; private set; }
		public IEnumerable<Ia32DisassemblyBlock> BlocksByAddress
		{
			get
			{
				return this.Blocks.OrderBy(b => b.BaseAddress);
			}
		}

		public IEnumerable<NativeDependency> Dependencies { get; private set; }
	}
}
